var voiceidone=""; //上一个播放的audio标签的id
var serceridone = '';
var localId = '';
var serverId = 0;
window.scrollH = '';
var groupId = "<?=$this->data['群id']?>";
var hproseUrl = "<?=STATISTICS_URL?>";
var is_luyin = 0; //是否在录音
//var images = {
//    localId: [],
//    serverId: []
//};

var u = navigator.userAgent, app = navigator.appVersion;
var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Linux') > -1; //android终端或者uc浏览器
var isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/); //ios终端
var isClickHistory = false;

hproseMethods = [
    'MsgController_msgList',
    'CourseController_listenRecord',
    'CourseController_onlineTimes'
];
var hproseClient = hprose.Client.create(hproseUrl, hproseMethods);

wx.config({
    debug: false,
    appId: '<?php echo $this->signPackage["appId"];?>',
    timestamp: '<?php echo $this->signPackage["timestamp"];?>',
    nonceStr: '<?php echo $this->signPackage["nonceStr"];?>',
    signature: '<?php echo $this->signPackage["signature"];?>',
    jsApiList: [
        'startRecord',
        'stopRecord',
        'onRecordEnd',
        'playVoice',
        'pauseVoice',
        'stopVoice',
        'uploadVoice',
        'downloadVoice',
        'chooseImage',
        'previewImage',
        'uploadImage',
        'downloadImage',
        'onVoiceRecordEnd',
        'getNetworkType'
    ]
});

wx.ready(function(){
    wx.hideOptionMenu(); //隐藏右上角菜单接口
    wx.getNetworkType({
        success: function (res) {
            var networkType = res.networkType; // 返回网络类型2g，3g，4g，wifi
            if (networkType != 'wifi') {
                $("header").show();
            }
        }
    });
});

var appKey = "611d56bcd17bdfa4a83e5bdf55916589";
var account = "<?=$_SESSION['userCenter']['id']?>";
var token = "<?=$_SESSION['userCenter']['token']?>";
var chatId = "<?=$this->data['chatId']?>";
var chatroomObj;
var timeStamp = new Date().getTime();
var msgReturnNum; //单次实际返回消息数
var msgGetNum = 50; //单次获取历史消息数
var msgCountPerFlush = 0; //每次刷新返回的消息数
var var_message = ''; //每次刷新返回的消息html
var timeStamp_msg_history = get_unix_time('2016-11-7'); //有历史记录的时间
var timeStamp_course = get_unix_time('<?=$this->data["开始时间"]?>'); //课程时间

console.log(account);
console.log(token);

var nim = NIM.getInstance({
    debug: true,
    appKey: appKey,
    account: account,
    token: token,
    onconnect: onConnect
});

var online_time_interval = setInterval('online_time()', 10000); //记录在线时长

listenRecord(); //听课记录

$("header img").click(function(){
    $("header").hide();
});


//查看历史消息
$("#content").scroll(function(){
    if($("#content").scrollTop() == 0){
        msgCountPerFlush = 0; //每次刷新返回的消息数
        var_message = ''; //每次刷新返回的消息html
        window.scrollH = $("#content")[0].scrollHeight;
        isClickHistory = true;

        $(".freChat").show();
        if ($("#content").scrollTop() <= 0) {

            if (timeStamp_course > timeStamp_msg_history) {
                getHistoryMsgs(timeStamp);
            } else {
                chatroomObj.getHistoryMsgs({
                    timetag: timeStamp,  // 不填表示当前时间戳
                    limit: msgGetNum, //100条
                    done: getHistoryMsgsDone
                });
            }
        }

    }
});

//发文本
$("#send_text").click(function() {
    var text = $.trim($("#message").val());
    var msg = chatroomObj.sendText({
        text: text,
        done: sendChatroomMsgDone
    });
    $("#message").val("");
    $(".pictureBtn").show();
    $(".send").hide();
});


//发送图片
$(".pictureBtn").click(function(){
    if(isAndroid){
        $(".class_talk_con_header video").hide();
    }
    wx.chooseImage({
        count: 1, // 默认9
        sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
        sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
        success: function (res) {
            $(".class_talk_con_header video").show();
            localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片

            var localId = localIds.pop();
            wx.uploadImage({
                localId: localId,
                isShowProgressTips: 1,
                success: function (res) {
                    var imageId = res.serverId; // 返回图片的服务器端ID

                    re = common.get('group', 'downLoadWxFile', {'serverId':imageId, 'type':'image'});
                    console.log('下载图片：'+JSON.stringify(re));
                    if (re.result == 0) {
                        file = re.datas;
                        var msg = chatroomObj.sendFile({
                            file: file,
                            type : 'image',
                            done: sendChatroomMsgDone
                        });
                        console.log('正在发送聊天室Image消息, id=' + msg.idClient);
                    }
                }
            });
        }
    });
});

//开始录音
$(".startAudio").click(function(){
    startluyin();
    setTimeout(countdown(60),1000);
    auto_stop();
    $(this).hide();
    $(".sendAudio").show();
    $(".time-bg").show();
    $("#media")[0].pause();
});

//发送录音
$(".sendAudio").click(function(){
    clearTimeout(dingshi);
    stopluyin();
    footerfunction();
});

//表情列表
for(var i in emoji){
    console.log(emoji[i].file);
    var mess = "<span class='expression' val='"+i+"' style=''><img style='width: 24px;height: auto;padding:6px;' src='business/images/emoji/"+emoji[i].file+"' /></span>"
    $("#emojiTag").append(mess);
}

$(".expression").click(function(){
    var expression = $(this).attr('val');
    $(".send").show();
    $(".inputEmojiCon").show();
    $(".keyboardBtn").hide();
    $(".pictureBtn").hide();
    $("#emojiTagDiv").hide();
    $(".class_talk_con_footer").show();
    $("#message").val($("#message").val()+expression);
});

function onConnect() {
    console.log('连接成功');
    nim.getChatroomAddress({
        chatroomId: chatId,
        done: getChatroomAddressDone
    });
    function getChatroomAddressDone(error, obj) {
        console.log('获取聊天室地址' + (!error?'成功':'失败'), error, obj);
        if(!error){
            chatroomObj = Chatroom.getInstance({
                appKey: appKey,
                account: account,
                token: token,
                chatroomId: chatId,
                chatroomAddresses: obj.address,
                onconnect: onChatroomConnect,
                onerror: onChatroomError,
                onwillreconnect: onChatroomWillReconnect,
                ondisconnect: onChatroomDisconnect,
                // 消息
                onmsgs: onChatroomMsgs
            });
        }

    }
}

function onChatroomConnect(chatroom) {
    console.log('进入聊天室', chatroom);

    if (timeStamp_course > timeStamp_msg_history) {
        getHistoryMsgs(timeStamp);
    } else {
        chatroomObj.getHistoryMsgs({
            //timetag: 1451393192478,  // 不填表示当前时间戳
            limit: 50,
            done: getHistoryMsgsDone

        });
    }
}

//console.log('正在发送聊天室text消息, id=' + msg.idClient);
function sendChatroomMsgDone(error, msg) {
    console.log('发送聊天室' + msg.type + '消息' + (!error?'成功':'失败') + ', id=' + msg.idClient, error, msg);
    if(!error){
        getMessage(msg);
        footerfunction();
        write_chat_record(msg);
    }
}

//收到聊天室消息
function onChatroomMsgs(msgs) {
    var msg = msgs[0];
    getMessage(msg);
    if (msg.type == 'text' || msg.type == 'image' || msg.type == 'audio') {
        footerfunction();
    }
    console.log('收到聊天室消息', msgs);
}

//从自己的服务接口获取历史消息
function getHistoryMsgs(time) {
    hproseClient.MsgController_msgList(chatId, time, function(result) {
        for (i=0; i<result.result.length; i++) {
            tmsg = eval('('+ result.result[i] +')');

            msg = {};
            msg.type = tmsg.msgType;
            msg.fromAvatar = tmsg.fromAvator;
            msg.fromNick = tmsg.fromNick;
            msg.from = tmsg.fromAccount;
            msg.idClient = tmsg.msgidClient;
            msg.time = tmsg.msgTimestamp;

            timeStamp = msg.time;

            if (tmsg.msgType == 'TEXT') {
                msg.text = tmsg.attach;
                msg.type = 'text';
            } else if (tmsg.msgType == 'PICTURE') {
                msg.file = eval('('+ tmsg.attach +')');
                msg.type = 'image';
            } else if (tmsg.msgType == 'AUDIO') {
                msg.file = eval('('+ tmsg.attach +')');
                msg.type = 'audio';
            }
            var_message = message_html(msg) + var_message;
            console.log(msg);
        }
        //console.log(var_message);

        $("#content").prepend(var_message);
        $("#content").scrollTop($("#content")[0].scrollHeight - window.scrollH);
        $(".freChat").hide();

        if (isClickHistory == false) {
            footerfunction();
        }

    });
}

function getHistoryMsgsDone(error, obj) {
    console.log('获取聊天室历史' + (!error?'成功':'失败'), error, obj.msgs);
    msgReturnNum = obj.msgs.length;
    //if (msgReturnNum == msgGetNum) {
    //    $("#view_history_news").show();
    //} else {
    //    $("#view_history_news").hide();
    //}
    if(!error && obj.msgs.length > 0){
        for(var i=0;i<obj.msgs.length;i++) {
            var msg = obj.msgs[i];

            $(".no-comment").css('display', 'none');
            timeStamp = msg.time;

            if (msg.type == 'text' || msg.type == 'image' || msg.type == 'audio') {
                msgCountPerFlush++;
                var_message = message_html(msg) + var_message;
            }
        }

        if(msgReturnNum == msgGetNum && msgCountPerFlush < 10){
            chatroomObj.getHistoryMsgs({
                timetag: timeStamp,  //不填表示当前时间戳
                limit: msgGetNum,
                done: getHistoryMsgsDone
            });
        }else{
             $("#content").prepend(var_message);
             $("#content").scrollTop($("#content")[0].scrollHeight - window.scrollH);
             $(".freChat").hide();
        }

        if (isClickHistory == false) {
            footerfunction();
        }
    } else {
        $(".freChat").hide();
    }
}

/**
 * 返回消息html
 * @param type 类型 文本，图片，语音
 * @param avatar 头像
 * @param name 昵称
 * @param content 消息内容
 * @param timeStamp 消息时间戳
 * @returns {*}
 */
function message_html(msg) {

    type = msg.type;
    avatar = msg.fromAvatar;
    name = msg.fromNick;

    if (type == 'text') {
        msg.text = common.html_encode(msg.text);
        content = '<span class="newsCon">' + buildEmoji(msg.text) + '</span>';
        content = common.ReplaceUrl(common.html_decode(content));
    } else if (type == 'image') {

        max_width = document.documentElement.clientWidth * 0.7; //最大宽度

        if (msg.file.w > max_width) {
            img_width = max_width;
            img_height = max_width / (msg.file.w / msg.file.h)
        } else {
            img_height = msg.file.h;
            img_width = msg.file.w;
        }

        content = '<span class="newsCon image"><img src="'+ msg.file.url + '"onclick="imgbig(this)" width="'+img_width+'" height="'+img_height+'"></span>';
    } else if (type == 'audio') {
        var audio_id = msg.idClient;
        var audio_time = Math.ceil(msg.file.dur/1000);
        audio_time = audio_time > 60 ? 60 : audio_time;
        var from = msg.from;

        if (msg.file.url.indexOf('http://static.cyyzjk.com') > -1) {
            msg.file.url += '.mp3';
        }

        var voice1Width = audio_time*0.15+1+'rem';         
        if (from == account) {
            content =audio_xiaohongdian(audio_id) +'<i style="margin-right:0.1rem;">'+audio_time + 's' +'</i>'+'<span class="newsCon voice"  onclick="playaudio(\''+audio_id+'\',\''+from+'\')" style="width:'+voice1Width+'">' +  '<img src="business/style/chat_audio_static_r.png" alt=""> <audio  id="'+audio_id+'" src="'+msg.file.url+'" audio_time="'+ audio_time +'" ></audio> '+ '</span>';
           
        } else {
            content ='<span class="newsCon voice" onclick="playaudio(\''+audio_id+'\',\''+from+'\')"  style="width:'+voice1Width+'">' +'<img src="business/style/chat_audio_static.png" alt=""> <audio  id="'+audio_id+'" src="'+msg.file.url+'" audio_time="'+ audio_time +'" ></audio> ' +  '</span>'+'<i style="margin-left:0.1rem;">'+audio_time + 's' +'</i>'+ audio_xiaohongdian(audio_id);
        }
    }


    str = '';
    if (type == 'text' || type == 'image' || type == 'audio') {

        //自己发的消息
        if (msg.from == account) {
            str = "<div class='newsTime'>"+getTime(msg.time)+"</div>" +
            '<div class="newsTo news clearfix">' +
            '<div class="avatar">' +
            '<img src="'+avatar+'" >' +
            '</div>' +
            '<div class="newsOther">' +
            '<p class="name">'+name+'</p>' +
            content +
            '</div>' +
            '</div>';
        } else {
            str = "<div class='newsTime'>"+getTime(msg.time)+"</div>" +
            '<div class="newsFrom news clearfix">' +
            '<div class="avatar">' +
            '<img src="'+avatar+'" >' +
            '</div>' +
            '<div class="newsOther">' +
            '<p class="name">'+name+'</p>' +
            content +
            '</div>' +
            '</div>';
        }
    }
    return str;
}

function audio_xiaohongdian(audio_id) {
    str = '';
    if (common.getCookie(audio_id) == '') {
        str = '<img  red_id="'+audio_id+'"src="business/style/xiaohongdian.gif" alt="">';
    }
    return str;
}


//接收消息显示
function getMessage(msg){
    console.log("接收消息：" + JSON.stringify(msg));
    $('#content').append(message_html(msg));
}

function getTime(date){
    date = new Date(parseInt(date));
    // var year = date.getFullYear();
    var month = date.getMonth()+1;
    var day = date.getDate();
    var hour = date.getHours();
    var minute = date.getMinutes();
    //var second=date.getSeconds();
    if(month < 10){
        month = '0'+month;
    }
    if(day < 10){
        day = '0'+day;
    }
    if(hour < 10){
        hour = '0'+hour;
    }
    if(minute < 10){
        minute = '0'+minute;
    }
    //if(second < 10){
    //    second = '0'+second;
    //}
    return month+'-'+day+' '+hour+':'+minute;

}

function onChatroomWillReconnect(obj) {
    // 此时说明 `SDK` 已经断开连接, 请开发者在界面上提示用户连接已断开, 而且正在重新建立连接
    console.log('即将重连', obj);
}

function onChatroomDisconnect(error) {
    clearInterval(online_time_interval);
    // 此时说明 `SDK` 处于断开状态, 开发者此时应该根据错误码提示相应的错误信息, 并且跳转到登录页面
    console.log('连接断开', error);
    if (error) {
        switch (error.code) {
            // 账号或者密码错误, 请跳转到登录页面并提示错误
            case 302:
                break;
            // 被踢, 请提示错误后跳转到登录页面
            case 'kicked':
                break;
            default:
                break;
        }
    }
}

function onChatroomError(error, obj) {
    console.log('发生错误', error, obj);
}

function startluyin(){
    is_luyin = 1;
    wx.startRecord({
        cancel: function () {
            is_luyin = 0;
            alert('用户拒绝授权录音');
        }
    });
}

function stopluyin(){
    wx.stopRecord({
        success: function (res) {
            is_luyin = 0;
            send_record(res);
            closeAudio();
        },
        fail: function (res) {
            alert(JSON.stringify(res));
        }
    });
}

function stopluyin_only(){
    if (is_luyin == 1) {
        wx.stopRecord({
            success: function (res) {
                is_luyin = 0;
            },
            fail: function (res) {
                alert(JSON.stringify(res));
            }
        });
    }
}

function auto_stop(){
    wx.onVoiceRecordEnd({
        // 录音时间超过一分钟没有停止的时候会执行 complete 回调
        complete: function (res) {
            is_luyin = 0;
            send_record(res);
            closeAudio()
        }
    });
}

function close_audio_icon(voiceid, from) {
    if (from == account) {
        $("#"+voiceid).prev().attr("src", "business/style/chat_audio_static_r.png");
    } else {
        $("#"+voiceid).prev().attr("src", "business/style/chat_audio_static.png");
    }

}

function play_audio_icon(voiceid, from) {
    if (from == account) {
        $("#"+voiceid).prev().attr('src', 'business/style/chat_audio_play_r.gif');
    } else {
        $("#"+voiceid).prev().attr('src', 'business/style/chat_audio_play.gif');
    }
}


//播放声音
function playaudio(voiceid, from) {
    if($("#"+voiceid)[0].paused) {
        $("#"+voiceid)[0].play();
        play_audio_icon(voiceid, from);

        common.setCookie(voiceid, 1, 180);
        $("img[red_id='"+ voiceid +"']").remove();

        //播放完毕切换提示图标
        var aud = document.getElementById(voiceid);
        aud.onended = function(){
            close_audio_icon(voiceid, from);
        };

    } else {
        $("#"+voiceid)[0].pause();
        $("#"+voiceid)[0].currentTime = 0;
        close_audio_icon(voiceid, from);
    }

    // $("#"+serceridone).attr("ok1",0);
    if(voiceid != voiceidone && voiceidone.length > 0) {
        if(!$("#"+voiceidone)[0].paused){
            $("#"+voiceidone)[0].pause();
            $("#"+voiceidone)[0].currentTime=0;
            close_audio_icon(voiceidone, from);
        }
    }
    voiceidone = voiceid
}

//发送录音
function send_record(res){
    localId = res.localId;
    wx.uploadVoice({
        localId: localId,
        success: function (res) {
            serverId = res.serverId;
            re = common.get('group', 'downLoadWxFile', {'serverId':serverId});
            console.log('下载音频：'+JSON.stringify(re));
            if (re.result == 0) {
                file = re.datas;
                var msg = chatroomObj.sendFile({ 
                    file: file,
                    type : 'audio',
                    done: sendChatroomMsgDone
                });
                console.log('正在发送聊天室audio消息, id=' + msg.idClient);
            }
        }
    });
}


//保存聊天记录
function write_chat_record(msg) {
    if (msg.type == 'text') {
        type = '文本';
        message = msg.text;
    } else if (msg.type == 'image' ) {
        type = '图片';
        message = msg.file.url;
    } else if (msg.type == 'audio') {
        type = '语音';
        message = msg.file.url;
    } else {
        return false;
    }

    param = {
        'groupId' : groupId,
        'type' : type,
        'message' : message
    };
    re = common.post('course', 'write_chat_record', param);
    console.log('保存聊天记录：' + JSON.stringify(re));
}

//记录在线时长
function online_time() {
    common.post('group', 'out_group_lx', {'groupId':groupId});

    console.log("==记录在线时长==");
    hproseClient.CourseController_onlineTimes(
        chatId,  //卡片id
        "<?=$this->data['doTeacher']->get_userCenterID()?>", //老师id
        "<?=$this->data['doTeacher']->get_name()?>", //老师姓名
        "<?=$this->data['doUser']->get_userCenterID()?>", //用户id
        "<?=$this->data['doUser']->get_name()?>", //用户昵称
        "<?=$this->data['doUser']->get_头像()?>", //用户头像
        "<?=$this->data['doUserDoctor']->get_专业领域()?>", //科室
        "<?=$this->data['doUserDoctor']->get_职务()?>", //职称
        "<?=$this->data['doUser']->get_province()?>", //所在省
        "<?=$this->data['doUser']->get_city()?>", //所在市
        "<?=$this->data['doUserDoctor']->get_医院()?>", //医院
        "<?=$this->data['doUser']->get_telephone()?>", //电话
        10, //时间间隔，单位秒
        5, //类型 1，文章，2 动态，3, 病历 4，会议 5, 课堂 6, 广告
        1, //来源： 1:公众账号 2:app 3:官网
        "<?= $this->data['title']?>", //课程名称
        timeStamp_course, //课程开始时间
        function(result) {
            console.log(result);
        }
    );
}

//听课记录
function listenRecord() {
    console.log("==上报听课记录==");
    hproseClient.CourseController_listenRecord(
        chatId,  //卡片id
        "<?=$this->data['doTeacher']->get_userCenterID()?>", //老师id
        "<?=$this->data['doTeacher']->get_name()?>", //老师姓名
        "<?=$this->data['doUser']->get_userCenterID()?>", //用户id
        "<?=$this->data['doUser']->get_name()?>", //用户昵称
        "<?=$this->data['doUser']->get_头像()?>", //用户头像
        "<?=$this->data['doUserDoctor']->get_专业领域()?>", //科室
        "<?=$this->data['doUserDoctor']->get_职务()?>", //职称
        "<?=$this->data['doUser']->get_province()?>", //所在省
        "<?=$this->data['doUser']->get_city()?>", //所在市
        "<?=$this->data['doUserDoctor']->get_医院()?>", //医院
        "<?=$this->data['doUser']->get_telephone()?>", //电话
        5, //类型 1，文章，2 动态，3, 病历 4，会议 5, 课堂 6, 广告
        1, //来源： 1:公众账号 2:app 3:官网
        "<?= $this->data['title']?>", //课程名称
        timeStamp_course, //课程开始时间
        function(result) {
            console.log(result);
        }
    );
}

// 滑到最底部
function footerfunction(){
    $("#content")[0].scrollTop = $("#content")[0].scrollHeight;
}


//字体适配
(function(win,doc){
    function change(){
        doc.documentElement.style.fontSize=doc.documentElement.clientWidth/375*23.4375+'px';
    }
    change();
    win.addEventListener('resize',change,false);   
})(window,document);


// 显示图片放大效果
function imgbig(obj){
    // if(isAndroid){
    //     $(".vedio").hide();
    // }
    $("#imgbbig").show();
    $(".imgbbigdiv").show();
    var img=$(obj).attr('src');
    $(".pinch-zoom").find("img").attr("src",img);
    $('.video').hide();
    clearInterval(ds_video);
}

// 图片放大后关闭
function imgbigclose(){
    $("#imgbbig").hide();
    $(".imgbbigdiv").hide();
    $('.video').show();
    ds_video = setInterval('getConH()',400);
}

// 文本输入框的宽度
var sendHeight1 = $(".entering").width() - $(".audioBtn").outerWidth(true) - $(".send").outerWidth(true)-$(".inputEmojiCon").outerWidth(true)-4 ;
var sendHeight = $(".entering").width() - $(".audioBtn").outerWidth(true) - $(".pictureBtn").outerWidth(true)-$(".inputEmojiCon").outerWidth(true)-4;
var AudioBtnHeight = $(".entering").width() - $(".audioBtn").outerWidth(true)*2;
$(".entering .input").css("width", sendHeight);
$(".AudioBtn").css("width",AudioBtnHeight);

//显示录音按钮
$(".audioBtn").click(function(){
    var display = $(".keyboardBtn").css("display");
    if(display == 'none'){
        $(".enteringInput").hide();
        $(this).hide();
        $(".closeBtn").show();
        $(".startAudio").show();
        $(".pictureBtn").hide();
        $(".send").hide();
        $(".inputEmojiCon").hide();
        $(".keyboardBtn1").show();
    }else{
        $(".inputEmojiCon").show();
        $(".keyboardBtn").hide();
        $("#emojiTagDiv").hide();
    }
});


//隐藏录音按钮
$(".closeBtn").click(function(){
    closeAudio();
});

//关闭录音
function closeAudio(){
    $(".closeBtn").hide();
    $(".audioBtn").show();
    $(".pictureBtn").show();
    $(".closeBtn").hide();
    $(".startAudio").hide();
    $(".sendAudio").hide();
    $(".time-bg").hide();
    $(".enteringInput").show();
    $(".keyboardBtn1").hide();
    if(typeof(dingshi) !== "undefined"){
        clearTimeout(dingshi);
    }
    if($("#message").val().length>0){
        $(".pictureBtn").hide();
        $(".inputEmojiCon").show();
        $(".send").show();
    }else{
        $(".send").hide();
        $(".inputEmojiCon").show();
        $(".pictureBtn").show();
    }
    stopluyin_only();
}

// 左边键盘点击
$(".keyboardBtn1").click(function(){
     closeAudio();
})

// 倒计时
function countdown(变量) {
    $(".Audiotime").text(变量+"s");
    var now=变量-1;
    if(parseInt(变量) >0){
        dingshi=setTimeout(function () {
            countdown(now);
        }, 1000);
    }
}

// 表情的弹出
$(".entering .inputEmojiCon").click(function(){
    getConH();
    $("#emojiTagDiv").show();
    $(".inputEmojiCon").hide();
    $(".keyboardBtn").show();
    $(".send").hide();
    keyupMsg()
});


// 点击键盘事件
$(".keyboardBtn").click(function(){
    $(".keyboardBtn").hide();
    $("#emojiTagDiv").hide();
    $(".inputEmojiCon").show();
    $(".send").hide();
    keyupMsg();
});

//聊天内容的高度，表情的高度ii
function getConH(){
    var contentHeight=$(window).height()-$(".video").outerHeight(true)-$(".entering").outerHeight(true)+"px";
    var emojiTagHeight=$(".video").outerHeight(true)+"px";
    $("#content").css("height",contentHeight);
    $("#emojiTagDiv").css("top",emojiTagHeight);
    $("#emojiTagDiv").css("height",contentHeight);
    // $(".videoH").css("height",$(".video").outerHeight(true));
    // alert($(".video").outerHeight(true)+"..."+contentHeight)
}

getConH();

// 第一次播放重新获取高度
// $(window).scroll(function(){ 
//     getConH();
// });

// $("#content").scroll(function(){ 
//     event.stopPropagation();
// });
 
$("#message").focus(function(){
    $(".entering .input").css("width", sendHeight1);
    $("#emojiTagDiv").hide(); 
    $(".keyboardBtn").hide();
    $(".inputEmojiCon").show();
    // (function(win,doc){
    //     function change1(){
    //         $(".entering").css("position","absolute");
    //         $(".entering").css("bottom","0");
    //     }
    //     change1();
    //     win.addEventListener('resize',change1,false);   
    // })(window,document);

    // setTimeout(function(){
    //     $(".entering").css("position","absolute");
    //     $(".entering").css("bottom","0");
    //     $(document).scrollTop() = $(document).scrollHeight();
    // }, 3000);
});

$("#message").blur(function(){
    $(".entering").removeAttr("style");
    keyupMsg();
});

function keyupMsg(){
    if($("#message").val().length>0){
        $(".pictureBtn").hide();
        $(".send").show();
    }else{
        $(".pictureBtn").show();
        $(".send").hide();
    }
}

$("#message").keyup(function(){
    keyupMsg();
});


function get_unix_time(dateStr) {
    var newstr = dateStr.replace(/-/g,'/');
    var date =  new Date(newstr);
    var time_str = date.getTime().toString();
    return time_str.substr(0, 10);
}

/*
$("#media").click(function(){
    var var_1 = $(".video").outerHeight(true);
    var ds_video = setInterval(function(){
        var var_2 = $(".video").outerHeight(true);
        if (var_1 != var_2) {
            //getConH();
            //clearInterval(ds_video);
        }
    },1000);

});
*/

var ds_video;
ds_video = setInterval('getConH()',400);




